#!/usr/bin/env python
# -*-coding:utf-8 -*-
__author__ = 'whisky'
__date__ = '2019/1/14 17:23'

from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

class LoginRequiredMixin(object):       # super不能在经典类中使用，要声明新式类
    """
    重定义dispatch方法，在请求进来之前先由method_decorator装饰器执行验证用户是否登录，之后执行dispatch方法
    """
    @method_decorator(login_required(login_url='/login/'))
    def dispatch(self, request, *args, **kwargs):
        return super(LoginRequiredMixin, self).dispatch(request,*args,**kwargs)